package com.byCreation.t_globe;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import pl.mg6.android.maps.extensions.GoogleMap;
import pl.mg6.android.maps.extensions.GoogleMap.OnMapClickListener;
import pl.mg6.android.maps.extensions.SupportMapFragment;

import com.aretha.slidemenu.SlideMenu;
import com.byCreatetion.adabter.CardListAdapter;
import com.byCreatetion.adabter.ImageGalleryAdapter;
import com.byCreatetion.adabter.TglobeAppAdapter;
import com.byCreatetion.adabter.TouchImageView;
import com.byCreatetion.adabter.facilitiesAdapter;
import com.byCreation.Control.Control;
import com.byCreation.Control.LDObservableScrollView;
import com.byCreation.Control.SliderMenuLeft;
import com.byCreation.Profile.CompareActivity;
import com.byCreation.Profile.MyBookmarkActivity;
import com.byCreation.Profile.MyDiscountActivity;
import com.byCreation.Profile.MyHistoryActivity;
import com.byCreation.Profile.MyNoteActivity;
import com.byCreation.Profile.MySettingActivity;
import com.byCreation.Profile.MyprofileActivity;
import com.byCreation.Profile.TglobeAppActivity;
import com.byCreation.t_globe.ContentActivity.Load_AddNote;
import com.byCreation.t_globe.ContentActivity.Load_DATANote;
import com.byCreation.t_globe.R;
import com.capricorn.RayMenu;


import com.demo.t_globe.chart.SpiderWebChart;
import com.demo.t_globe.chart.TitleValueEntity;

import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.squareup.picasso.Picasso;

import Myclass.AllIntent;
import Myclass.ConnectInternet;
import Parser.HttpGetJson;
import Parser.SendToBD;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class CardDetailActivity extends BaseSlideMenuActivity
		implements
		com.byCreation.Control.LDObservableScrollView.LDObservableScrollViewListener,
		OnClickListener, AnimationListener, OnItemClickListener,OnMapClickListener {

	// SliderMenu
	private SlideMenu mSlideMenu;

	// ===============GoogleAnalytics==============
	private GoogleAnalytics mGaInstance;
	private Tracker mGaTracker;
	// =============================================
	// ===================================googleAnalytics=============================
	@Override
	public void onStart() {
	super.onStart();
	// The rest of your onStart() code.
	EasyTracker.getInstance().activityStart(this); // Add this method.
	mGaTracker.sendView("CardDetail Screen");

	}

	

// =================================================================	
	
	
	
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		EasyTracker.getInstance().activityStop(this); // Add this method.

		Control.Call_From_Note=false;
		super.onStop();
	}

	// =====Gallery
	private Gallery gallery;
	private ImageGalleryAdapter galleryAdapter;
	private LinearLayout lay_bggallery, Li_1, Li_2, Li_4, Li_5;
	public static ArrayList<String> List_IMAGES = new ArrayList<String>();
	public static ArrayList<HashMap<String, Object>> MyArrList_gallery = new ArrayList<HashMap<String, Object>>();
	private HashMap<String, Object> map = new HashMap<String, Object>();

	// ======Gotomap
	private LinearLayout lay_tomap;

	// ======Intent

	AllIntent intent = new AllIntent(CardDetailActivity.this);

	// ===Expancell
	private final int CELL_DEFAULT_HEIGHT = 200;
	private final int NUM_OF_CELLS = 30;

	// ====Type Room

	private HorizontalScrollView horizontalScrollView_expan1,
			horizontalScrollView_expan2, horizontalScrollView_expan3;
	private Animation anim_expan_in, anim_expan_out;

	// ===TabView
	private FrameLayout btn_tab1, btn_tab2;
	private RelativeLayout Laytab_1, Laytab_2, Laytab_3;

	// ==Chart
	SpiderWebChart spiderwebchart;

	// main menu
	private FrameLayout lay_munu, laymap;
	private Animation anim_menu_show, anim_menu_hide;

	// Text
	TextView txt_card_desc, txt_name, txt_address, txt_call, txt_email,
			txt_web, txt_business;

	// img
	ImageView img_bar;

	// map
	private GoogleMap mMap;

	// UIL

	private ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();
	private ImageLoader imageLoader = ImageLoader.getInstance();
	private DisplayImageOptions options;
	
	
	
	
	
	//Profile
	private ImageView img_profile_menu1,img_profile_menu2,img_profile_menu3,
	img_profile_menu4,img_profile_menu5,img_profile_menu6,img_profile_menu7,
	img_profile_menu8,img_profile_menu9,img_user;
	
	private LinearLayout txt_next,txt_register;
	private FrameLayout Laylogin;
	private ConnectInternet connect=new ConnectInternet(CardDetailActivity.this);
	
	
	
	
	
	
	//Gridview facilities
	private GridView facilities_gridView;
	private ArrayList<HashMap<String, Object>> facilitiesAdapter_MyArrList;
	private HashMap<String, Object> map_facilities = new HashMap<String, Object>();
	private facilitiesAdapter facilities_adapter;
	

	@Override
	public void onContentChanged() {
		super.onContentChanged();
		Log.e("Test", "SlideMenuAttribute");

		setSlideRole(R.layout.activity_card_detail);
		setSlideRole(R.layout.layout_primary_menu);
		setSlideRole(R.layout.fagment_profile);
		
		SetSliderMenu();
		
		
		// =============================GoogleAnalytics=========================
		mGaInstance = GoogleAnalytics.getInstance(this);
		mGaTracker = mGaInstance.getTracker(Control.IDGoogleanalytics);
		
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}

		
		
		if(Control.Call_From_Note&&new ConnectInternet(this).checkInternetConnection())
			new Load_DATANote().execute();
		

		Control.Pointers="CardDetail";
		SetViewProfile();
		setUpMapIfNeeded();
		SetView();
		SetTab();		
		SetScollView();
		SetAceMunu();
		
		
		
	}
	
	
	SliderMenuLeft slide;
	private void SetSliderMenu() {
		// TODO Auto-generated method stub
		mSlideMenu = getSlideMenu();

		mSlideMenu.setEdgeSlideEnable(true);
		mSlideMenu.setEdgetSlideWidth(Control.setEdgetSlideWidth);
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth(); // deprecated
		int height = display.getHeight(); // deprecated

		
		RelativeLayout rl = (RelativeLayout) findViewById(R.id.R1);
		RelativeLayout r2 = (RelativeLayout) findViewById(R.id.R2);

		rl.getLayoutParams().width = width - 100;
		r2.getLayoutParams().width = width - 100;
		slide=new SliderMenuLeft(this,true,mSlideMenu);
		
	}


	
	
	
	public void SetAceMunu() {
		// TODO Auto-generated constructor stub
		
	    int[] ITEM_DRAWABLES = { 
	    		R.drawable.card_detail_btn_compare_1,
	    		R.drawable.card_detail_btn_bookmark_1,
	    		R.drawable.card_detail_btn_note_1,
	    		R.drawable.card_detail_btn_share_1,};
		
		RayMenu rayMenu = (RayMenu)findViewById(R.id.ray_menu);
        final int itemCount = ITEM_DRAWABLES.length;
		for (int i = 0; i < itemCount; i++) {
			ImageView item = new ImageView(CardDetailActivity.this);
			item.setImageResource(ITEM_DRAWABLES[i]);

			final int position = i;
			rayMenu.addItem(item, new OnClickListener() {

				@Override
				public void onClick(View v) {
				//	Toast.makeText(CardDetailActivity.this, "position:" + position, Toast.LENGTH_SHORT).show();
				
					if(new ConnectInternet(CardDetailActivity.this).checkInternetConnection())
					{
					
					
						if(position==0)
						{
							new Load_AddToCompare().execute();
						}
						if(position==1)
						{
							new Load_AddBookmark().execute();
						}
						if(position==2)
						{
							new Load_DATANote().execute();
						}
					
						if(position==3)
						{
							//
							AllIntent intent=new AllIntent(CardDetailActivity.this);
	                		intent.ShareDG("http://www.t-globe.com/"+Control.page_id, "");
						}
					
					
						}
				}
			});// Add a menu item
		}
		
	}
	
	private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
        	FragmentManager fm =  getSupportFragmentManager();
    		SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    		mMap = f.getExtendedMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
               // setUpMap();
            	
            	
            }
        }
    }

    /**
     * This is where we can add markers or lines, add listeners or move the camera. In this case, we
     * just add a marker near Africa.
     * <p>
     * This should only be called once and when we are sure that {@link #mMap} is not null.
     */
	
	
	public static LatLng latlng;
	public static String MapTitle="";
	
    @SuppressWarnings("deprecation")
	private void setUpMap(final double lat,final double lng) {
  
    	 MapTitle=name;
    	 latlng=new LatLng(lat, lng);
    	 mMap.setOnMapClickListener(this);
    	 mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)).title(name)).showInfoWindow();
    	 mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10.0f));
    	 
    	 
    	try{
    	mMap.getUiSettings().setScrollGesturesEnabled(false);
    	
    	mMap.getUiSettings().setZoomControlsEnabled(false);
    	mMap.getUiSettings().setZoomGesturesEnabled(false);
        
        
        final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView();
        mapView.setOnClickListener(this);
        
        
		 if (mapView.getViewTreeObserver().isAlive()) {
	            mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
	                @SuppressWarnings("deprecation") // We use the new method when supported
	                @SuppressLint("NewApi") // We check which build version we are using.
	                @Override
	                public void onGlobalLayout() {
	                    
	                	
	                	
	                	
	                	  LatLngBounds.Builder builder = new LatLngBounds.Builder();
	                	  LatLngBounds tmpBounds = null;
	                	
	                	    builder.include(new LatLng(lat,lng));
	                	    tmpBounds = builder.build();
	                	
                       
	                    
	                    
	                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
	                      mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
	                    } else {
	                      mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
	                    }
	                    //mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(tmpBounds, 50));
	                    
	                }
	            });
	        }
		 mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 13.0f));
		
   
    	
    	} catch (Exception ex){Log.e("ERROR",""+ex.toString());}
    }
	@Override
	public void onMapClick(LatLng position) {
		// TODO Auto-generated method stub
		startActivity(new Intent(CardDetailActivity.this,MapActivity.class));
		
	}
	
	
	
	private int Tab_index=1;
	private void SetTab() {
		// TODO Auto-generated method stub
		btn_tab1=(FrameLayout)findViewById(R.id.btn_tab1);
		btn_tab2=(FrameLayout)findViewById(R.id.btn_tab2);

		
		Laytab_1=(RelativeLayout)findViewById(R.id.Laytab_1);
		Laytab_2=(RelativeLayout)findViewById(R.id.Laytab_2);
		Laytab_3=(RelativeLayout)findViewById(R.id.Laytab_3);
		
		
		btn_tab1.setOnClickListener(this);
		btn_tab2.setOnClickListener(this);
		
		Chk_ShowTab();
		
	}
	private void Chk_ShowTab() {
		// TODO Auto-generated method stub
		if(Tab_index==1)
		{
			Laytab_1.setVisibility(View.VISIBLE);
			Laytab_2.setVisibility(View.GONE);
			Laytab_3.setVisibility(View.GONE);
			
			btn_tab1.setBackgroundResource(R.drawable.custom_button_tab_a);
			btn_tab2.setBackgroundResource(R.drawable.custom_button_tab_n);
			
			
		}
		if(Tab_index==2)
		{
			Laytab_1.setVisibility(View.GONE);
			Laytab_2.setVisibility(View.VISIBLE);
			Laytab_3.setVisibility(View.GONE);
			
			btn_tab1.setBackgroundResource(R.drawable.custom_button_tab_n);
			btn_tab2.setBackgroundResource(R.drawable.custom_button_tab_a);
			
			
		}
	
		
		
		
		
		
	}
	
	
	
	private int diff=-1;
	@Override
	public void onScrollChanged(LDObservableScrollView scrollView, int x,int y, int oldx, int oldy) {
		// TODO Auto-generated method stub
		View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
		 diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
		if(diff==0&&lay_munu.getVisibility()==View.INVISIBLE)
		{
			//Log.e("TG", "SCROLL END");
			ShowMenu();
		}
		
	}
	
	
	float Y_Down=0.0f;
	float Y_Move=0.0f;
	float Y_Up=0.0f;
	private void SetScollView()
	{
		
		
		
		    LDObservableScrollView scroll_content=(LDObservableScrollView)findViewById(R.id.scrollView_content);
			scroll_content.setScrollViewListener(this);
			
			
			
			scroll_content.setOnTouchListener(new OnTouchListener() {
	
		        public boolean onTouch(View v, MotionEvent event) {
	
		            if (event.getAction() == MotionEvent.ACTION_DOWN) {
		            	
		            	
		            	//Log.e("TG","y Down="+event.getY());
		            	Y_Down=event.getY();
		            }
		            
		            
		            if (event.getAction() == MotionEvent.ACTION_MOVE) {
		            	
		            	
		            	//Log.e("TG","y Move="+event.getY());
		            	Y_Move=event.getY();
		            		
		            }
		            
		            if(event.getAction() == MotionEvent.ACTION_UP)
		            {
		            	
		            	if(Y_Down-Y_Move>150&&diff!=0&&lay_munu.getVisibility()==View.VISIBLE)
		            	{
		            		HideMenu();
		            	}
		            	if(Y_Down-Y_Move<150&&lay_munu.getVisibility()==View.INVISIBLE)
		            	{
		            		ShowMenu();
		            	}	
		            	
		            }
		            return false;
		        }
			});  
		        
	
	}
	private void ShowMenu() {
		// TODO Auto-generated method stub
			
			
			lay_munu.setVisibility(View.VISIBLE);
			lay_munu.startAnimation(anim_menu_show);
		
		}
	private void HideMenu() {
			// TODO Auto-generated method stub
		

			lay_munu.setVisibility(View.INVISIBLE);
			lay_munu.startAnimation(anim_menu_hide);
	}
	
	
	
	
	
	private void initSpiderWebChart()
    {
        this.spiderwebchart = (SpiderWebChart)findViewById(R.id.spiderwebchart);
        
		List<TitleValueEntity> data1 = new ArrayList<TitleValueEntity>();
		data1.add(new TitleValueEntity("Service ",rating1));
		data1.add(new TitleValueEntity("Clean ",rating2));
		data1.add(new TitleValueEntity("Facilites ",rating3));
		data1.add(new TitleValueEntity("Location ",rating4));
		data1.add(new TitleValueEntity("Price ",rating5));
		
		
		
		List<List<TitleValueEntity>> data = new ArrayList<List<TitleValueEntity>>();
		data.add(data1);
		
		
		spiderwebchart.setData(data);
		spiderwebchart.setLatitudeNum(5);
    }
	
	
	
	
	
	
	
	
	
	

	
	private void SetView() {
		// ===========top menu
				ImageView img_back=(ImageView)findViewById(R.id.img_back);
				img_back.setOnClickListener(this);
				
		
				
				
		//=======Gallery
				gallery = (Gallery)findViewById(R.id.gallery);
				gallery.setOnItemClickListener(this);
				
				if(new ConnectInternet(this).checkInternetConnection())
				{
					new LoadContentFromServer().execute();
					new LoadCardDetail().execute();
				}
		// Intent 
				Li_1=(LinearLayout)findViewById(R.id.Li_1);
				Li_2=(LinearLayout)findViewById(R.id.Li_2);
				Li_4=(LinearLayout)findViewById(R.id.Li_4);
				Li_5=(LinearLayout)findViewById(R.id.Li_5);
				Li_1.setOnClickListener(this);
				Li_2.setOnClickListener(this);
				Li_4.setOnClickListener(this);
				Li_5.setOnClickListener(this);
				
				
	    //=======Laymenu
				lay_tomap=(LinearLayout)findViewById(R.id.lay_tomap);
				lay_tomap.setOnClickListener(this);
				
				
		//lay_munu
				anim_menu_show = AnimationUtils.loadAnimation(CardDetailActivity.this, R.anim.anim_menu_show);
				anim_menu_hide = AnimationUtils.loadAnimation(CardDetailActivity.this, R.anim.anim_menu_hide);
				 lay_munu=(FrameLayout)findViewById(R.id.lay_munu);
				 laymap=(FrameLayout)findViewById(R.id.laymap);
				 laymap.setOnClickListener(this);
				 
				 
				 //===========Data
				 
					txt_card_desc=(TextView)findViewById(R.id.txt_card_desc);
					txt_name=(TextView)findViewById(R.id.txt_name);
					txt_address=(TextView)findViewById(R.id.txt_address);
					txt_call=(TextView)findViewById(R.id.txt_call);
					txt_email=(TextView)findViewById(R.id.txt_email);
					txt_web=(TextView)findViewById(R.id.txt_web);
					txt_business=(TextView)findViewById(R.id.txt_business);
					
					
					img_bar=(ImageView)findViewById(R.id.img_bar);
			
					
					
					//======UIL

			        options = new DisplayImageOptions.Builder()
					.showStubImage(R.drawable.imgtemp )
					.showImageForEmptyUri(R.drawable.imgtemp)
					.showImageOnFail(R.drawable.imgtemp)
					.delayBeforeLoading(100)
			        .cacheInMemory()
					.cacheOnDisc()
					.bitmapConfig(Bitmap.Config.RGB_565)
					.displayer(new RoundedBitmapDisplayer(0))
					.build();
				initImageLoader(CardDetailActivity.this);
					
					
		

				
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}


	@Override
	public void onAnimationRepeat(Animation animation) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onAnimationEnd(Animation animation) {
		// TODO Auto-generated method stub
		/*if(index_expan==1)
		{
			img_typeroom1.setVisibility(View.GONE);
		}
		else
		if(index_expan==2)
		{
			img_typeroom2.setVisibility(View.GONE);
		}
		else
		if(index_expan==3)
		{
			img_typeroom3.setVisibility(View.GONE);
		}*/
	}

	
	
	
	@Override
	public void onAnimationStart(Animation animation) {
		// TODO Auto-generated method stub
		
		
	}
	
	
	
	
	
	
	@SuppressWarnings("deprecation")
	@Override
	public void onClick(View v) {

		
		if (v.getId() == R.id.img_back) {

			CardDetailActivity.this.finish();
		} 


		if(v.getId()==R.id.lay_tomap||v.getId()==R.id.map)
		{
			
			//startActivity(new Intent(CardDetailActivity.this, MapActivity.class));
			//CardDetailActivity.this.finish();
		}
		
		
		
		
	
		//=====tab
		if(v.getId()==R.id.btn_tab1)
		{
			Tab_index=1;
			Chk_ShowTab();
		}
		if(v.getId()==R.id.btn_tab2)
		{
			Tab_index=2;
			Chk_ShowTab();
		}
		
		
		
		
		//======Intent
		if(v.getId()==R.id.Li_1)
		{
			if(!web.equals(""))
			{
					Intent i = new Intent(Intent.ACTION_VIEW);
					i.setData(Uri.parse(web)); 
					this.startActivity(i);
			}
			else
				Toast.makeText(CardDetailActivity.this," Data_empty ", 900).show();
		
		}
		if(v.getId()==R.id.Li_2)
		{
			
//			Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.brochure);
//	        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//	        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
//
//	        File f = new File(Environment.getExternalStorageDirectory()
//	                + File.separator + "test.jpg");
//	        try {
//	            f.createNewFile();
//	            FileOutputStream fo = new FileOutputStream(f);
//	            fo.write(bytes.toByteArray());
//	            fo.close();
//	        } catch (IOException e) {
//	            e.printStackTrace();
//	        }
//
//
//	        Uri path = Uri.fromFile(f);
//	        Intent intent = new Intent();
//	        intent.setAction(Intent.ACTION_VIEW);
//	        intent.setDataAndType(path, "image/*");
//	        startActivity(intent);
		}
		
		if(v.getId()==R.id.Li_4)
		{
			if(!tel.equals(""))
			{
				try{
					Intent i = new Intent(Intent.ACTION_DIAL);
			        i.setData(Uri.fromParts("tel", tel.replace("-",""), "#")); 
			        this.startActivity(i);
				} catch (Exception e) {
					Toast.makeText(CardDetailActivity.this,e.toString(), 900).show();
				}
			}
			else
				Toast.makeText(CardDetailActivity.this," Data_empty ", 900).show();
			
		}
		if(v.getId()==R.id.Li_5)
		{
			if(!email.equals(""))
			{
			Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",email, null));
			emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
			this.startActivity(Intent.createChooser(emailIntent, "Send email..."));
			}
			else
				Toast.makeText(CardDetailActivity.this," Data_empty ", 900).show();
		}
		
		
		
		
		
		
		
		
		//======Profile
//		//================Menu==============
				if(v.getId()==R.id.img_profile_menu1)
				{
					startActivity(new Intent(CardDetailActivity.this,MyHistoryActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu2)
				{
					startActivity(new Intent(CardDetailActivity.this,MyBookmarkActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu3)
				{
					startActivity(new Intent(CardDetailActivity.this,MyNoteActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu4)
				{
					//startActivity(new Intent(MainActivity.this,MyCompareActivity.class));
					startActivity(new Intent(CardDetailActivity.this,CompareActivity.class));
					
				}
				if(v.getId()==R.id.img_profile_menu5)
				{
					startActivity(new Intent(CardDetailActivity.this,MyNoteActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu6)
				{
					startActivity(new Intent(CardDetailActivity.this,TglobeAppActivity.class));
				}
				
				if(v.getId()==R.id.img_profile_menu7)
				{
					startActivity(new Intent(CardDetailActivity.this,MyDiscountActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu8)
				{
					startActivity(new Intent(CardDetailActivity.this,MySettingActivity.class));
				}
				if(v.getId()==R.id.img_profile_menu9)
				{
					Control.Loginstatus=false;
					Control.UserName="";
					Control.UserPassword="";
					SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	

					Editor editor = sharedpreferences.edit();
					editor.putString("Username", Control.UserName);
					editor.putString("Password", Control.UserPassword);
					
					
					Log.e("tglobe","======Logout=======");

					Log.e("tglobe",sharedpreferences.getString("Username", ""));
					Log.e("tglobe",sharedpreferences.getString("Password", ""));
					CardDetailActivity.this.finish();
					startActivity(new Intent(CardDetailActivity.this,LoginActivity.class));
				}

				
				
				if(v.getId()==R.id.img_user)
				{

					startActivity(new Intent(CardDetailActivity.this,MyprofileActivity.class));
				}
		
		
		
	}

	

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id) {
		// TODO Auto-generated method stub
		//Show_Dialog_Photo();
		PhotoActivity.index_photo=position;
		startActivity(new Intent(CardDetailActivity.this,ViewPagerPhotoViewActivity.class));
	}
	
	
	
	
	
	//===============================LoadContent=============================================
  	class LoadContentFromServer extends AsyncTask<Object, Integer, Object> {

  		boolean Cancelled=false;
		private String Exception="";
		
	
 		
 		@SuppressWarnings("null")
 		@Override
 		protected Object doInBackground(Object... params) {

 		
 			  try {
					
					JSONObject jsonObj=null;
					jsonObj = new JSONObject(HttpGetJson.GetJson(Control.getAPI_GalleryDetail(Control.carddetail_id,Control.carddetail_name).replace(" ","%20"),
							Control.user,
							Control.pass));
					
					JSONObject Data=jsonObj.getJSONObject("data");
					JSONArray jsonarray_data=Data.getJSONArray("img");
					 for (int i = 0; i <jsonarray_data.length(); i++)
					 { 
						 
						 map = new HashMap<String, Object>();
						 map.put("img","http://"+jsonarray_data.getString(i));
					     MyArrList_gallery.add(map);
					     
					     Log.e("TG", "img_cardDetail:"+jsonarray_data.getString(i));
					 }
					
			   } catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Exception=e.getMessage();
				
			   } catch (Exception e) {
					// TODO: handle exception
				   Exception=e.getMessage();
			   }
 			
 		
 		  
 			return null;
 		}

 		
 		@Override
	    protected void onCancelled() {
			
			Cancelled=true;
	       
	    }
		
 		
 		@Override
 		protected void onPreExecute() {
 			galleryAdapter=new ImageGalleryAdapter(CardDetailActivity.this, MyArrList_gallery);
 			gallery.setAdapter(galleryAdapter);
 			
 			super.onPreExecute();
 		}

 		@Override
 		public void onProgressUpdate(Integer... progress) {

 			Log.e("star", "progressupdate");
 		}

 		@Override
 		protected void onPostExecute(Object result) {
 			
 			
 			if(!Cancelled)
 			{
 				gallery.setSelection(2);
 				galleryAdapter.notifyDataSetChanged();
 			}
 			else
				Toast.makeText(CardDetailActivity.this, Exception, 2000).show();

 		
 		}
 	}




  private String name="",email="",web="",tel="",address="",img="",
		  card_desc="";

  
  
  
  double longitude;
double latitude;
				  
  	
  	
  	
  	
  private int	rating1=5,rating2=5,rating3=5,rating4=5,rating5=5;
  	
  	
  	
  	
  	
  	ProgressBar progressBar1;
  	int SumRat=0;
	class LoadCardDetail extends AsyncTask<Object, Integer, Object> {
		private boolean OnCancle=false;
		@Override
		protected void onCancelled() {
			// TODO Auto-generated method stub
			OnCancle=true;
			super.onCancelled();
		}

		@SuppressWarnings("null")
		@Override
		protected Object doInBackground(Object... params) {

			
	    try {
	    	
	    	   String ss=Control.getAPI_Card_detail(Control.carddetail_id,Control.carddetail_name).replace(" ","%20");
	    	
	    	   Log.e("tg", "getAPI_CardDetail="+HttpGetJson.GetJson(ss,Control.user,Control.pass));
			  
	    	   
	    	    JSONObject jsonObj=null;
				jsonObj = new JSONObject(HttpGetJson.GetJson(ss,Control.user,Control.pass));

				
				JSONArray jsonarray_content=jsonObj.getJSONArray("card_detail");
			
			
				for (int i = 0; i <jsonarray_content.length(); i++)
				{
					JSONObject jsonObj_content=jsonarray_content.getJSONObject(i);
					try {name=jsonObj_content.getString("name");} catch (Exception e) {e.printStackTrace();}
						
					
					
					try {email=jsonObj_content.getString("email");} catch (Exception e) {e.printStackTrace();}
					try {web=jsonObj_content.getString("web");} catch (Exception e) {e.printStackTrace();}
					try {tel=jsonObj_content.getString("tel");} catch (Exception e) {e.printStackTrace();}
					try {address=jsonObj_content.getString("address");} catch (Exception e) {e.printStackTrace();}
					try {latitude=Double.parseDouble(jsonObj_content.getString("latitude"));} catch (Exception e) {e.printStackTrace();}
					try {longitude=Double.parseDouble(jsonObj_content.getString("longitude"));} catch (Exception e) {e.printStackTrace();}
					try {img=jsonObj_content.getString("img");} catch (Exception e) {e.printStackTrace();}
					try {rating1=Integer.parseInt(jsonObj_content.getString("rating1"));} catch (Exception e) {e.printStackTrace();}
					try {rating2=Integer.parseInt(jsonObj_content.getString("rating2"));} catch (Exception e) {e.printStackTrace();}
					try {rating3=Integer.parseInt(jsonObj_content.getString("rating3"));} catch (Exception e) {e.printStackTrace();}
					try {rating4=Integer.parseInt(jsonObj_content.getString("rating4"));} catch (Exception e) {e.printStackTrace();}
					try {card_desc=jsonObj_content.getString("card_desc");} catch (Exception e) {e.printStackTrace();}
			
					
					SumRat=(rating1+rating2+rating3+rating4)/4;
					
					
					
					//facilities
					JSONArray jsonarray_facilities=jsonObj_content.getJSONArray("facilities");
					Log.e("TG2","=facilities="+jsonarray_facilities);
					
					
					for (int i2 = 0; i2 <jsonarray_facilities.length(); i2++)
					{
						
						
						map_facilities = new HashMap<String, Object>();

						
						JSONObject jsonObj_facilities=jsonarray_facilities.getJSONObject(i2);

						map_facilities.put("img",jsonObj_facilities.getString("icon_path"));
						map_facilities.put("icon_name",jsonObj_facilities.getString("icon_name"));

						
						Log.e("TG2","icon_path"+jsonObj_facilities.getString("icon_path"));
						Log.e("TG2","icon_name"+jsonObj_facilities.getString("icon_name"));
					    
						facilitiesAdapter_MyArrList.add(map_facilities);

						
					}
					
					
					
				}
		
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			
			
				 
			return null;
		}

		@Override
		protected void onPreExecute() {

			
			progressBar1=(ProgressBar)findViewById(R.id.progressBar1);
			progressBar1.setVisibility(View.VISIBLE);
			
			
			
			//====facilites
			facilities_gridView = (GridView)findViewById(R.id.facilities_gridView);
		    facilitiesAdapter_MyArrList = new ArrayList<HashMap<String, Object>>();
		    if (facilities_adapter == null) {
		    	facilities_adapter = new facilitiesAdapter(CardDetailActivity.this, facilitiesAdapter_MyArrList);
			    facilities_gridView.setAdapter(facilities_adapter);

		    }
		    
		    
			Log.e("tg", "onPreExecute()");
			
			

			
			super.onPreExecute();
		}

		@Override
		public void onProgressUpdate(Integer... progress) {

			Log.e("star", "progressupdate");
			
			
		}

		@Override
		protected void onPostExecute(Object result) {
			
			if(!OnCancle)
			{			
				setUpMap(latitude,longitude);
				initSpiderWebChart();
				txt_card_desc.setText(card_desc);
				txt_name.setText(name);
				txt_address.setText(address);
				txt_call.setText(tel);
				txt_email.setText(email);
				txt_web.setText(web);
				txt_business.setText("");
				
				RatingBar  ratingBar1=(RatingBar)findViewById(R.id.ratingBar1);
				ratingBar1.setRating(SumRat);
				
				
				if(!img.equals(""))
				{
					
					try {Picasso.with(CardDetailActivity.this) .load("http://"+img).into(img_bar);}catch (Exception e) {e.printStackTrace();}
			//try {imageLoader.displayImage(img, img_bar, options, animateFirstListener);}catch (Exception e) {e.printStackTrace();}
				}
				
				
				//====facilites
				runOnUiThread (new Thread(new Runnable() { 
			         public void run() {
			        	 facilities_adapter.notifyDataSetChanged();      
			         }}));
				
				
				
				
				progressBar1.setVisibility(View.INVISIBLE);
			}
			
		
		}

	}



	
	
	  public  void initImageLoader(Context context) {
	  		// This configuration tuning is custom. You can tune every option, you may tune some of them, 
	  		// or you can create default configuration by
	  		//  ImageLoaderConfiguration.createDefault(this);
	  		// method.
	  		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
			  		.memoryCacheExtraOptions(100, 200) // default = device screen dimensions
			        .threadPoolSize(2) // default
			        .threadPriority(Thread.NORM_PRIORITY - 1) // default
			        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
			        .denyCacheImageMultipleSizesInMemory()
			        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
			        .memoryCacheSize(2 * 1024 * 1024)
			        .discCacheSize(50 * 1024 * 1024)
			        .discCacheFileCount(100)
			        .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
			        .imageDownloader(new BaseImageDownloader(context)) // default
			       
			       
			        .build();
	  		// Initialize ImageLoader with configuration.
	  		ImageLoader.getInstance().init(config);
	  	}
	  	
	    
	  	@SuppressWarnings("unused")
		private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {

			 final static List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());

			@Override
			public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
				if (loadedImage != null) {
					ImageView imageView = (ImageView) view;
					boolean firstDisplay = !displayedImages.contains(imageUri);
					if (firstDisplay) {
						FadeInBitmapDisplayer.animate(imageView, 500);
						displayedImages.add(imageUri);
					}
				}
			}
		}


	  //================SetProfileMenu====================
		
		
	  		private void SetViewProfile() {
	  			// TODO Auto-generated method stub
	  		
	  			
	  			Laylogin=(FrameLayout)findViewById(R.id.Laylogin);
	  			if(!Control.Loginstatus)
	  				Laylogin.setVisibility(View.VISIBLE);
	  			
	  			
	  			//=======menu
	  			img_profile_menu1=(ImageView)findViewById(R.id.img_profile_menu1);
	  			img_profile_menu2=(ImageView)findViewById(R.id.img_profile_menu2);
	  			img_profile_menu3=(ImageView)findViewById(R.id.img_profile_menu3);
	  			img_profile_menu4=(ImageView)findViewById(R.id.img_profile_menu4);
	  			img_profile_menu5=(ImageView)findViewById(R.id.img_profile_menu5);
	  			img_profile_menu6=(ImageView)findViewById(R.id.img_profile_menu6);
	  			img_profile_menu7=(ImageView)findViewById(R.id.img_profile_menu7);
	  			img_profile_menu8=(ImageView)findViewById(R.id.img_profile_menu8);
	  			img_profile_menu9=(ImageView)findViewById(R.id.img_profile_menu9);
	  			
	  			img_user=(ImageView)findViewById(R.id.img_user);
	  			img_user.setOnClickListener(this);
	  			img_user=(ImageView)findViewById(R.id.img_user);
	  			img_user.setOnClickListener(this);
	  			
	  			

	  			TextView txt_username=(TextView) findViewById(R.id.txt_username);
	  			txt_username.setText(Control.UserName);
	  			
	  			
	  			try {
					
	  				
	  				
	  				Log.e("Picasso", "=========Picasso() ==========");
	  				
	  				if(Control.Img_profile.equals(""))
	  				{
	  					img_user.setImageResource(R.drawable.btn_menu_top_righ);

	  				}
	  				else
	  				{
	  					Bitmap myBitmap = BitmapFactory.decodeFile(Control.Img_profile_Path);
	  					img_user.setImageBitmap(myBitmap);
	  				}
	  				
	  				
	  				
	  				} catch (Exception e) {
	  					img_user.setImageResource(R.drawable.btn_menu_top_righ);
	  				}
	  			
	  			
	  			
	  			img_profile_menu1.setOnClickListener(this);
	  			img_profile_menu2.setOnClickListener(this);
	  			img_profile_menu3.setOnClickListener(this);
	  			img_profile_menu4.setOnClickListener(this);
	  			img_profile_menu5.setOnClickListener(this);
	  			img_profile_menu6.setOnClickListener(this);
	  			img_profile_menu7.setOnClickListener(this);
	  			img_profile_menu8.setOnClickListener(this);
	  			img_profile_menu9.setOnClickListener(this);

	  			
	  			
	  			//=========Login
	  			txt_next=(LinearLayout)findViewById(R.id.txt_next);
	  			txt_next.setOnClickListener(this);
	  			
	  			txt_register=(LinearLayout)findViewById(R.id.txt_register);
	  			txt_register.setOnClickListener(this);
	  			
	  			
	  			ImageView img_tglobe_login=(ImageView)findViewById(R.id.img_tglobe_login);
	  			img_tglobe_login.setOnClickListener(this);
	  			
	  			ImageView img_facebook =(ImageView)findViewById(R.id.img_facebook);
	  			img_facebook.setOnClickListener(this);
	  			
	  			
	  			
	  		}



	  		public void ShowDialog_Note_Read()
			{
				
				final Dialog dialog = new Dialog(CardDetailActivity.this,android.R.style.Theme_Translucent_NoTitleBar);
				//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
				//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
				dialog.setContentView(R.layout.dialog_note_read);
		        dialog.setCancelable(true);
		        dialog.show();
		       
		       TextView txt_note_title=(TextView)dialog.findViewById(R.id.txt_note_title);
		       txt_note_title.setText(editText_title);
		       
		       TextView txt_note_data=(TextView)dialog.findViewById(R.id.txt_note_data);
		       txt_note_data.setText(Text_Note);
		        
		        
			}
			
			
			private String Text_Note="",editText_title="";
			class Load_DATANote extends AsyncTask<Object, Integer, Object> {

				  

				private ProgressDialog mProgressDialog3;
				private String title,content,images,date,link,result,desc;
				private boolean Cancle=false;
				
				  @Override
				protected void onCancelled() {
					// TODO Auto-generated method stub
					  Cancle=true;
					super.onCancelled();
				}
				@SuppressWarnings("null")
				@Override
				protected Object doInBackground(Object... params) {

					try {
						 ArrayList<String> arrayList_parametor=new ArrayList<String>();
						 ArrayList<String> arrayList_value=new ArrayList<String>();
						
						 arrayList_parametor.add("cardid");
						 arrayList_value.add(Control.carddetail_id);
							
						 arrayList_parametor.add("username");
						 arrayList_value.add(Control.UserName);
				
						 arrayList_parametor.add("cardname");
						 arrayList_value.add(Control.carddetail_name);
						
						 
						 SendToBD sd=new SendToBD(CardDetailActivity.this);
						 String respone=sd.send(
									Control.user, 
									Control.pass, 
									Control.getAPI_LoadNoteCard(),
									arrayList_parametor,
									arrayList_value);
							
							JSONObject jsonObj;
							jsonObj = new JSONObject(respone);
							
							JSONArray array_note=jsonObj.getJSONArray("notes");
							
							 JSONObject jsonObj_data=array_note.getJSONObject(0);
							
							 editText_title=jsonObj_data.getString("title");
							 Text_Note=jsonObj_data.getString("note");
						
						 
						} catch (JSONException e) {
							
							e.printStackTrace();
						
						}
					return null;
				}
						

				@Override
				protected void onPreExecute() {

					 //=====================ProgressDialog==========================
					if(mProgressDialog3==null)
					{
				        mProgressDialog3 = new ProgressDialog(CardDetailActivity.this);
				        mProgressDialog3.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
				        mProgressDialog3.setMessage("Save Note....");                       
				    	mProgressDialog3.setCancelable(true);
					}
					
					if(mProgressDialog3!=null)
						mProgressDialog3.show();
					
					
					
					super.onPreExecute();
				}

				@Override
				public void onProgressUpdate(Integer... progress) {

					Log.e("star", "progressupdate");
					
					
				}

				@Override
				protected void onPostExecute(Object result) {
					
					if(!Cancle)
					{
						
						if(Control.Call_From_Note)
							ShowDialog_Note_Read();
						else
							ShowDialog_Note();
						
						Toast.makeText(CardDetailActivity.this, desc, 800).show();

					}
					
				if(mProgressDialog3!=null)
					mProgressDialog3.hide();
				}

			}
			
				
			class Load_AddNote extends AsyncTask<Object, Integer, Object> {

				  

				private ProgressDialog mProgressDialog3;
				private String title,content,images,date,link,result,desc;
				private boolean Cancle=false;
				
				  @Override
				protected void onCancelled() {
					// TODO Auto-generated method stub
					  Cancle=true;
					super.onCancelled();
				}
				@SuppressWarnings("null")
				@Override
				protected Object doInBackground(Object... params) {

					try {
						 ArrayList<String> arrayList_parametor=new ArrayList<String>();
						 ArrayList<String> arrayList_value=new ArrayList<String>();
						
						 arrayList_parametor.add("cardid");
						 arrayList_value.add(Control.carddetail_id);
							
						 arrayList_parametor.add("username");
						 arrayList_value.add(Control.UserName);
				
						 arrayList_parametor.add("title");
						 arrayList_value.add(editText_title);
				
						 arrayList_parametor.add("cardname");
						 arrayList_value.add(Control.carddetail_name);
						 
						 
						 
						 arrayList_parametor.add("notes");
						 arrayList_value.add(Text_Note);
				
						 
						 Log.e("TG","Save Note:"+Control.page_id+":"+Control.UserName+":"+Text_Note);
						 
						 
						 SendToBD sd=new SendToBD(CardDetailActivity.this);
						 String respone=sd.send(
									Control.user, 
									Control.pass, 
									Control.getAPI_SaveNote_Card(),
									arrayList_parametor,
									arrayList_value);
							
							JSONObject jsonObj;
							jsonObj = new JSONObject(respone);
							
							
							Log.e("tg","desc="+jsonObj.getString("desc"));
						
							desc=jsonObj.getString("desc");
							
							
							
							
						
						 
						} catch (JSONException e) {
							
							e.printStackTrace();
						
						}
					return null;
				}
						

				@Override
				protected void onPreExecute() {

					 //=====================ProgressDialog==========================
					if(mProgressDialog3==null)
					{
				        mProgressDialog3 = new ProgressDialog(CardDetailActivity.this);
				        mProgressDialog3.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
				        mProgressDialog3.setMessage("Save Note....");                       
				    	mProgressDialog3.setCancelable(true);
					}
					
					if(mProgressDialog3!=null)
						mProgressDialog3.show();
					
					
					
					super.onPreExecute();
				}

				@Override
				public void onProgressUpdate(Integer... progress) {

					Log.e("star", "progressupdate");
					
					
				}

				@Override
				protected void onPostExecute(Object result) {
					
					if(!Cancle)
					{
						Toast.makeText(CardDetailActivity.this, desc, 800).show();

					
					
						if(mProgressDialog3!=null)
							mProgressDialog3.hide();
						}
					}

			}
			
			public void ShowDialog_Note()
			{
				
				final Dialog dialog = new Dialog(CardDetailActivity.this,android.R.style.Theme_Translucent_NoTitleBar);
				//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
				//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
				dialog.setContentView(R.layout.dialog_note);
		        dialog.setCancelable(true);
		        dialog.show();
		       
		        final EditText edt=(EditText)dialog.findViewById(R.id.editText_note);
		        final EditText edt2=(EditText)dialog.findViewById(R.id.editText_title);
		        edt.setText(Text_Note);
		        edt2.setText(editText_title);
		        
		       
		        
		        dialog.findViewById(R.id.lay_save).setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) { 
						
						
						Text_Note=edt.getText().toString();
						
						
						editText_title=edt2.getText().toString();
						
						if(new ConnectInternet(CardDetailActivity.this).checkInternetConnection())
						new Load_AddNote().execute();
					}
				});
		        
		        
			}
	  			
			class Load_AddToCompare extends AsyncTask<Object, Integer, Object> {

				  

				private ProgressDialog mProgressDialog3;
				private String title,content,images,date,link,result,desc;
				private boolean Cancle=false;
				
				  @Override
				protected void onCancelled() {
					// TODO Auto-generated method stub
					  Cancle=true;
					super.onCancelled();
				}
				@SuppressWarnings("null")
				@Override
				protected Object doInBackground(Object... params) {

					try {
						 ArrayList<String> arrayList_parametor=new ArrayList<String>();
						 ArrayList<String> arrayList_value=new ArrayList<String>();
						
						 arrayList_parametor.add("pageid");
						 arrayList_value.add(Control.page_id);
							
						
						  arrayList_parametor.add("cardid");
						 arrayList_value.add(Control.carddetail_id);
						 
						 arrayList_parametor.add("cardname");
						 arrayList_value.add(Control.carddetail_name);
						
						
						 arrayList_parametor.add("username");
						 arrayList_value.add(Control.UserName);
				
						 
						 Log.e("TG","Load_AddToCompare:"+Control.page_id+":"+Control.UserName+":"+Control.carddetail_id);
						 
						 
						 SendToBD sd=new SendToBD(CardDetailActivity.this);
						 String respone=sd.send(
									Control.user, 
									Control.pass, 
									Control.getAPI_AddToCompare(),
									arrayList_parametor,
									arrayList_value);
							
							JSONObject jsonObj;
							jsonObj = new JSONObject(respone);
							
							
							Log.e("tg","desc="+jsonObj.getString("desc"));
						
							desc=jsonObj.getString("desc");
							
							
							
							
						
						 
						} catch (JSONException e) {
							
							e.printStackTrace();
						
						}
					return null;
				}
						

				@Override
				protected void onPreExecute() {

					 //=====================ProgressDialog==========================
					if(mProgressDialog3==null)
					{
				        mProgressDialog3 = new ProgressDialog(CardDetailActivity.this);
				        mProgressDialog3.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
				        mProgressDialog3.setMessage("Add To Compare....");                       
				    	mProgressDialog3.setCancelable(true);
					}
					
					if(mProgressDialog3!=null)
						mProgressDialog3.show();
					
					
					
					super.onPreExecute();
				}

				@Override
				public void onProgressUpdate(Integer... progress) {

					Log.e("star", "progressupdate");
					
					
				}

				@Override
				protected void onPostExecute(Object result) {
					
					if(!Cancle)
					{
						Toast.makeText(CardDetailActivity.this, desc, 800).show();

					}
					
				if(mProgressDialog3!=null)
					mProgressDialog3.hide();
				}

			}
			
			class Load_AddBookmark extends AsyncTask<Object, Integer, Object> {

				  

				private ProgressDialog mProgressDialog2;
				private String desc;
				private boolean Cancle=false;
				
				  @Override
				protected void onCancelled() {
					// TODO Auto-generated method stub
					  Cancle=true;
					super.onCancelled();
				}
				@SuppressWarnings("null")
				@Override
				protected Object doInBackground(Object... params) {

					String title=Control.carddetail_name.replace(" ","%20");
					try {
						JSONObject jsonObj=null;
						jsonObj = new JSONObject(HttpGetJson.GetJson(Control.getAPI_AddTobookmark_Card(Control.carddetail_id,title, Control.UserName),Control.user,Control.pass));
						
					//Log.e("TG",(HttpGetJson.GetJson(Control.getAPI_AddTobookmark(Control.page_id, Control.UserName),Control.user,Control.pass)));

					
				    desc=jsonObj.getString("desc");
				  
				    
				    
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
						 
					return null;
				}

				@Override
				protected void onPreExecute() {

					 //=====================ProgressDialog==========================
					if(mProgressDialog2==null)
					{
				        mProgressDialog2 = new ProgressDialog(CardDetailActivity.this);
				        mProgressDialog2.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
				        mProgressDialog2.setMessage("Loading......");                       
				    	mProgressDialog2.setCancelable(true);
					}
					
					if(mProgressDialog2!=null)
						mProgressDialog2.show();
					
					
					
					super.onPreExecute();
				}

				@Override
				public void onProgressUpdate(Integer... progress) {

					Log.e("star", "progressupdate");
					
					
				}

				@Override
				protected void onPostExecute(Object result) {
					
					if(!Cancle)
					{
						Toast.makeText(CardDetailActivity.this, desc, 800).show();

					}
					
				if(mProgressDialog2!=null)
					mProgressDialog2.hide();
				}

			}
			
			
			
			
			
			
	
}
